package demo0914;

import java.util.concurrent.ArrayBlockingQueue;

class MyThreadPool {
    private ArrayBlockingQueue<Runnable> tasks = new ArrayBlockingQueue<>(1000);
    public MyThreadPool(int n) throws InterruptedException {
        for (int i = 0; i < n; i++) {
            Thread thread = new Thread(()->{
                try {
                    Runnable runnable = tasks.take();
                    runnable.run();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
            thread.start();
        }
    };
    public void submit (Runnable runnable) throws InterruptedException {
        tasks.put(runnable);
    }

}

public class T3_0523 {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool myThreadPool = new MyThreadPool(10);
        for (int i = 0; i < 500; i++) {
            int id = i;
            myThreadPool.submit(()->{
                System.out.println("this thred id：" + id);
            });
        }
    }
}
